<template>
    <van-loading  v-if="loging" size="0.5rem"/>
      <van-icon 
      v-else
      :color="obj.is_collected ? 'yellow' : '#777'"
      :name="obj.is_collected ? 'star' : 'star-o'"
       @click='btn'
        />
</template>

<script>
import {deleteCollect , addCollect} from '@/api/article'
export default {
name : 'Collect',
  props: {
    obj : {
        typeof :Object,
        required : true
    }
  },
  data () {
    return {
        loging : false
    }
  },
  methods: {
  async  btn(){
   try {
    this.loging= !this.loging
       if(this.obj.is_collected) {
        //调取消收藏
      await  deleteCollect(this.obj.art_id)
        this.obj.is_collected = !this.obj.is_collected
    }else {
       await addCollect(this.obj.art_id)
        this.obj.is_collected = !this.obj.is_collected
    }
   } finally {
    this.loging= !this.loging
   }
    }
  }
}
</script>

<style>

</style>